<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="../../vue-2.7.10/vue.js"></script>
</head>

<body>

</body>
<script>
    let vm = new Vue({
        data: {
            position: {
                x: 0,
                y: 0,

            },
            radius: 2,
        },
        //桥梁——转换成字符串后再转换成对象
        computed: {
            computedPosition() {
                return JSON.parse(JSON.stringify(this.position));
            }

        },
        watch: {
            position: {
                handler(newValue, oldValue) {
                    console.log(`新坐标是(${newValue.x},${newValue.y}),旧坐标是(${oldValue.x},${oldValue.y})`)
                },
                immediate: true,
                deep: true,
            },
            computedPosition: {
                handler(newValue, oldValue) {
                    console.log(`新坐标是(${newValue.x},${newValue.y}),旧坐标是(${oldValue.x},${oldValue.y})`)
                },
                immediate: true,
                deep: true,
            }
        }
    });
    vm.position.x = 3;
</script>

</html>